package leetcode;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * 描述:216. 组合总和 III
 *
 * @author Madison You
 * @created 1:12
 */
public class Mid_216_CombinationSum3 {
    public static void main(String[] args) {
        new Mid_216_CombinationSum3().combinationSum3(3, 7);
    }

    List<List<Integer>> list = new ArrayList<>();

    List<Integer> temp = new ArrayList<>();

    public List<List<Integer>> combinationSum3(int k, int n) {
        back(k, n, 1);
        return list;
    }

    private void back(int k, int n, int u) {
        if (temp.size() == k && n == 0) {
            list.add(new ArrayList<>(temp));
            return;
        }
        for (int i = u; i <= 9; i++) {
            temp.add(i);
            back(k, n - i, i + 1);
            temp.remove(temp.size() - 1);
        }
    }

    private int sum(List<Integer> temp) {
        int i = 0;
        for (Integer integer : temp) {
            i += integer;
        }
        return i;
    }
}
